package com.example.springmvc.controller;

import com.example.springmvc.model.UserInfo;
import jdk.nashorn.internal.runtime.regexp.joni.ast.StringNode;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/4/23 10:03
 */
@RestController
public class LoginController {
    @RequestMapping("/login")
    public HashMap<String,Object> login(@RequestBody UserInfo userInfo){
        HashMap<String,Object> json = new HashMap<>();
        int state = 200;
        int data = -1;
        String msg = "未知错误";
        if (StringUtils.hasLength(userInfo.getUsername()) && StringUtils.hasLength(userInfo.getPassword())){
            if (userInfo.getUsername().equals("admin") && userInfo.getPassword().equals("1234")){
                data = 1;
                msg = "";
            }else {
                msg="用户名或者密码失败！";
            }
        }else {
            msg="非法参数";
        }
        json.put("state",state);
        json.put("data",data);
        json.put("msg",msg);
        return json;
    }

}
